﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NB_Controller_Test
{
    class LogDataItem
    {
        #region
        private string _empty = "";

        private UInt32 _Index;        

        private String _LogSeq;
        private String _LogSaveId;
        private String _LogId;
        private string _Time;
        private String _Module;
        private String _Level;
        private String _LogDesc;
        private String _Log;

        public string Empty
        {
            get { return _empty; }
            set { _empty = value; }
        }

        public UInt32 Index
        {
            get { return _Index; }
            set { _Index = value; }
        }
        public string LogSeq
        {
            get { return _LogSeq; }
            set { _LogSeq = value; }
        }
        public string LogSaveId
        {
            get { return _LogSaveId; }
            set { _LogSaveId = value; }
        }
        public string LogId
        {
            get { return _LogId; }
            set { _LogId = value; }
        }
        public string Time
        {
            get { return _Time; }
            set { _Time = value; }
        }
        public string Module
        {
            get { return _Module; }
            set { _Module = value; }
        }
        public string Level
        {
            get { return _Level; }
            set { _Level = value; }
        }
        public string LogDesc
        {
            get { return _LogDesc; }
            set { _LogDesc = value; }
        }
        public string Log
        {
            get { return _Log; }
            set { _Log = value; }
        }        
        #endregion

        public LogDataItem()
        {

        }

        public LogDataItem(UInt32 index, JToken jtLogItems)
        {
            /*
             * //09:50:49 364  [192.168.137.114 : 59876] 
                BE BE BE BE 
                01 00 00 B2 00 00 00 00 00 64 01 03 
                {
                  "reqId": 1,
                  "leftItems": 1,
                  "err": 0,
                  "items": [
                    {
                      "logSeq": 213,
                      "logSaveId": 99,
                      "logId": 4,
                      "time": "18-08-22 15:48:11",
                      "module": "LAMP",
                      "level": "Error",
                      "logDescId": 0,
                      "log": "bri=10by wifi"
                    }
                  ]
                }
                ED ED 
             * */
            _Index = index;

            if (jtLogItems != null)
            {
                JToken jtLogSeq = jtLogItems.First.SelectToken("logSeq");
                if (jtLogSeq != null)
                {
                    _LogSeq = jtLogSeq.ToString();
                }

                JToken jtLogSaveId = jtLogItems.First.SelectToken("logSaveId");
                if (jtLogSaveId != null)
                {
                    _LogSaveId = jtLogSaveId.ToString();
                }

                JToken jtLogId = jtLogItems.First.SelectToken("logId");
                if (jtLogId != null)
                {
                    _LogId = jtLogId.ToString();
                }

                JToken jtTime = jtLogItems.First.SelectToken("time");
                if (jtTime != null)
                {
                    _Time = jtTime.ToString();
                }

                JToken jtModule = jtLogItems.First.SelectToken("module");
                if (jtModule != null)
                {
                    _Module = jtModule.ToString();
                }

                JToken jtLevel = jtLogItems.First.SelectToken("level");
                if (jtLevel != null)
                {
                    _Level = jtLevel.ToString();
                }

                JToken jtLogDescId = jtLogItems.First.SelectToken("logDescId");
                if (jtLogDescId != null)
                {
                    _LogDesc = jtLogDescId.ToString();
                }

                JToken jtLog = jtLogItems.First.SelectToken("log");
                if (jtLog != null)
                {
                    _Log = jtLog.ToString();
                }
            }            
        }
    }
}
